﻿#region Using

using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Asah.SiteWorx.BlogEngine.Core;

#endregion

public partial class Blog_Widgets_RecentPosts_Edit : WidgetEditBase
{
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            StringDictionary settings = GetSettings();
            if (settings.ContainsKey("numberofposts"))
                txtNumberOfPosts.Text = settings["numberofposts"];
            else
                txtNumberOfPosts.Text = "10";

            if (settings.ContainsKey("showcomments"))
                cbShowComments.Checked = settings["showcomments"].Equals("true", StringComparison.OrdinalIgnoreCase);

            if (settings.ContainsKey("showrating"))
                cbShowRating.Checked = settings["showrating"].Equals("true", StringComparison.OrdinalIgnoreCase);
        }
    }

    public override void Save()
    {
        StringDictionary settings = GetSettings();
        settings["numberofposts"] = txtNumberOfPosts.Text;
        settings["showcomments"] = cbShowComments.Checked.ToString();
        settings["showrating"] = cbShowRating.Checked.ToString();
        SaveSettings(settings);
        HttpRuntime.Cache.Remove("widget_recentposts");
    }
}
